package com.wash.shoes.entity;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.model.BaseModel;
import com.ruoyi.common.utils.StringUtils;
import com.wash.shoes.util.WashDateUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author ljg
 * @since 2024-08-28
 */
@ApiModel(value = "清洗得鞋子")
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("os_shoe")
public class ShoePo extends Model<ShoePo> {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "鞋子的id")
    @Excel(name = "id")
    private String id;

    @ApiModelProperty(value = "店铺的id")
    @Excel(name = "店铺的id")
    private String shopId;


    @ApiModelProperty(value = "物品类型 衣服  鞋子 item_type")
    @TableField("item_type")
    @Excel(name = "物品类型")
    private String itemType;

    @Excel(name = "货架id")
    @ApiModelProperty(value = "货架id")
    private String srgId;

    @Excel(name = "货架编码")
    @ApiModelProperty(value = "货架编码")
    private String srgCode;

    @ApiModelProperty(value = "水洗码 年月日+门店编号+随机生成5为数字就好了 2024082701xxxxx")
    @Excel(name = "水洗码")
    private String washCode;

    @ApiModelProperty(value = "清洗门店")
    @Excel(name = "清洗门店")
    private String washShop;

    @ApiModelProperty(value = "订单号")
    @Excel(name = "订单号")
    private String orderNumber;

    @Excel(name = "订单id")
    @ApiModelProperty(value = "订单id")
    private String orderId;

    @Excel(name = "清洗类型")
    @ApiModelProperty(value = "类型 奢洗")
    private String washType;

    @ApiModelProperty(value = "鞋子图片,逗号分隔")
    private String picture;

    @ApiModelProperty(value = "轮播图片,逗号分隔")
    private String carouselPicture;

    @Excel(name = "电话号码")
    @ApiModelProperty(value = "电话号码")
    private String phone;

    @Excel(name = "状态")
    @ApiModelProperty(value = "0待清洗 1清洗中 2清洗完成")
    private Integer status;
    @Excel(name = "备注")
    @ApiModelProperty(value = "备注")
    private String remark;
    //返回给前端的
    @TableField(exist = false)
    private List<String> remarks;
    @Excel(name = "入库时间")
    @ApiModelProperty(value = "入库时间")
    private Date storageTime;

    @ApiModelProperty(value = "入库人")
    private String storageUser;

    /**
     * 在列表中的第一个 1/3
     */
    @TableField(exist = false)
    private String index;
    /**
     * 0 不齐 1齐
     */
    @TableField(exist = false)
    private String complete = "";
    @Excel(name = "入库人")
    @ApiModelProperty(value = "入库人名字")
    private String storageUserName;
    @Excel(name = "清洗完成时间")
    @ApiModelProperty(value = "清洗完成时间")
    private String finishTime;

    @ApiModelProperty(value = "扩展字段")
    private String extendInfo;

    @TableField(value = "create_by", fill = FieldFill.INSERT)
    @ApiModelProperty(value = "创建者")
    private String createBy;

    @TableField(value = "create_time", fill = FieldFill.INSERT)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @ApiModelProperty(value = "创建时间")
    private Date createTime;

    @TableField(value = "update_by", fill = FieldFill.INSERT_UPDATE)
    @ApiModelProperty(value = "更新者")
    private String updateBy;

    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @ApiModelProperty(value = "更新时间")
    private Date updateTime;
    @Excel(name = "入库开始时间")
    @ApiModelProperty(value = "入库开始时间")
    private String startTime;
    @Excel(name = "入库结束时间")
    @ApiModelProperty(value = "入库结束时间")
    private String endTime;
    //add by jjz 2025年9月7日 16:36:18 添加字段 begin
    @ApiModelProperty(value = "清洗工厂")
    @Excel(name = "清洗工厂")
    @TableField("wash_factory")
    private String washFactory;

    @Excel(name = "质检时间")
    @ApiModelProperty(value = "质检时间")
    @TableField("quality_inspection_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime qualityInspectionTime;

    @ApiModelProperty(value = "质检人")
    @TableField("quality_inspector")
    private String qualityInspector;
    @Excel(name = "质检状态")
    @ApiModelProperty(value = "质检状态  0：未质检 1：已质检")
    @TableField("is_inspect")
    private String qualityInspectorStatus;
    @ApiModelProperty(value = "配饰")
    @TableField(exist = false)
    private List<AccessorVo> accessorVoList;
    
    @Excel(name = "配饰")
    @TableField(exist = false)
    private String accessoryStr;

    public void setAccessorVoList(List<AccessorVo> accessorVoList) {
        this.accessorVoList = accessorVoList;
        if (CollectionUtil.isNotEmpty(accessorVoList)) {
            this.accessoryStr = accessorVoList.stream().map(AccessorVo::getType).collect(Collectors.joining(","));
        }
    }
//    增加清洗工厂、物品类型、配饰、备注、质检时间、质检人、质检状态

    public void setStartTime(String startTime) {
        this.startTime = WashDateUtil.c1(startTime);
    }

    public void setEndTime(String endTime) {
        this.endTime = WashDateUtil.c1(endTime);
    }

    public void setRemark(String remark) {
        this.remark = remark;
        if (StringUtils.isNotEmpty(remark)) {
            try {
                this.remarks = JSONUtil.toList(remark, String.class);
            } catch (Exception e) {
            }
        }
    }

    /**
     * 配饰返回对象
     */

    @Data
    public static class AccessorVo extends BaseModel {
        @ApiModelProperty(value = "配饰id")
        private String id;
        @ApiModelProperty(value = "配饰水洗码")
        private String washCode;
        @ApiModelProperty(value = "配饰类型")
        private String type;
        @ApiModelProperty(value = "质检状态 0 未质检 1已质检")
        private int status;
    }
}
